@layout("/common/default.html",{title:'业务列表'}){

<fieldset class="table-search-fieldset">
    <legend>搜索信息</legend>
    <div style="margin: 10px 10px 10px 10px">
        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">选择数据表</label>
                    <div class="layui-input-inline">
                        <#select path="name" items="${table}" value="${table}" value="${genTable.name!}" lay-verify="true" lay-filter="selectTable" lay-search="true" placeholder="直接选择或搜索选择"/>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-primary layui-btn-radius" lay-submit lay-filter="search">
                        <i class="layui-icon"></i> 搜 索
                    </button>

                    <button type="button" class="layui-btn icon-btn layui-btn-radius" data-type="add">
                        <i class="layui-icon">&#xe654;</i>添加
                    </button>
                </div>
            </div>
        </form>
    </div>
</fieldset>


<table class="layui-table" id="gentableId" lay-filter="tableFilter" ></table>



<script type="text/html" id="table-toolbar">
    <a class="layui-btn layui-btn-primary layui-btn-xs  layui-btn-radius" lay-event="edit"><i
            class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-radius" lay-event="del"><i
            class="layui-icon layui-icon-delete"></i>删除</a>
</script>

<script>
    layui.use(['element','table', 'form',  'openLayer', 'miniTab','utils'], function () {
        var table = layui.table,
            form = layui.form,
            openLayer = layui.openLayer,
            miniTab = layui.miniTab,
            element=layui.element,
            utils = layui.utils;

        var tableData = table.render({
            elem: "#gentableId",
            url: "/gen/genTable/dataList",
            page: true,
            limit: 10,
            height: 'full-220',
            /* toolbar: "#toolbarTpl",*/
            cols: [[
                {type: 'numbers',title: '序号', fixed: 'left'},
                {field: 'name', title: '数据表名称', minWidth: 100},
                {field: 'comments', title: '描述'},
                {field: 'className', title: '类名称'},
                {field: 'createDate', title: '添加时间', sort: true},
                {title: "操作",  align: "center", templet: "#table-toolbar"}
            ]],
            done: function (res, curr, count) {
            }
        });

        form.on("submit(search)", function (data) {
            tableData.reload({
                where: data.field,
            });
            return false;
        });


        table.on("tool(tableFilter)", function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case "edit":
                    edit(data);
                    break;
                case "del":
                    del(data.id);
                    break;
            }
        });


        function edit(data) {
            var href = '/gen/genTable/add?id=' + data.id + '&name=' + data.name+'&op=edit';
            // 打开新的窗口
            miniTab.openNewTabByIframe({
                href:href,
                title:"字段配置",
            });
        }

        function del(id) {
            openLayer.confirm("确定要删除吗？", function () {
                utils.ajax("/gen/genTable/delete?id="+ id, "post").done(function (result) {
                    if(result.code=="0"){
                        utils.tableSuccessMsg(result.msg);
                    }else {
                        utils.tableSuccessMsg("删除失败");
                    }
                    tableData.reload();
                }).fail(function (error) {
                });
            })
        }

        //事件
        var active = {
            add: function () {
                // 打开新的窗口
                miniTab.openNewTabByIframe({
                    href:"/gen/genTable/add?op=add",
                    title:"字段配置",
                });
            },
        };
        $('[data-type]').click(function(){
            var type = $(this).data('type');
            active[type].call(this);
        });

    })
</script>
@}
